;
(function() {
  'use strict';
  angular.module('services.accessSystem.packetLoss', [])
    .service('packetLossService', packetLossService);

  function packetLossService(Restangular, $filter) {
    return {
      businessQuery: businessQuery,
      lostSceneQuery: lostSceneQuery,
      packetLossQuery: packetLossQuery,
      sendData: sendData,
      sendTitle: sendTitle
    };
    //报文记录丢失查询
    function packetLossQuery(params, callback) {
      Restangular.all('sas/accessSystem/packetLoss/query').post(params).then(callback);
    }
    //查询业务渠道
    function businessQuery(callback) {
      Restangular.one('sas/accessSystem/business/query').get().then(callback);
    }
    //查询丢失场景
    function lostSceneQuery(callback) {
      Restangular.one('sas/accessSystem/lostScene/query').get().then(callback);
    }

    function sendData(send) {
      var sendData = {
        startTime: $filter('date')(send.startTime, 'yyyy-MM-dd'),
        endTime: $filter('date')(send.endTime, 'yyyy-MM-dd'),
        business: send.business,
        lostScene: send.lostScene,
        serialNum: send.serialNum
      };
      return sendData;
    }

    function sendTitle(send, businessCodes, lostSceneCodes) {
      var title = '';
      var businessName = '';
      var lostSceneName = '';
      var startTime = $filter('date')(send.startTime, 'yyyy年MM月dd日');
      var endTime = $filter('date')(send.endTime, 'yyyy年MM月dd日');
      angular.forEach(businessCodes, function(item) {
        if (send.business === item.businessCode) {
          businessName = item.businessName;
        }
      });
      angular.forEach(lostSceneCodes, function(item) {
        if (send.lostScene === item.lostSceneCode) {
          lostSceneName = item.lostSceneName;
        }
      });
      if (startTime === endTime) {
        title = startTime + businessName  + lostSceneName + '情况统计';
      } else {
        title = startTime + '至' + endTime + businessName  + lostSceneName + '情况统计';
      }
      return title;
    }
  }

})();